<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 不要求会自己写插件，会使用别人写好的插件 -->
    <div id="app">
      <h2>插件 - {{count}}</h2>
      <child></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const app = createApp({
        inject: ["count"],
        data() {
          return {};
        },
        mounted() {
          console.log(this.a);
          this.fn();
        },
      });

      // 使用use方法来使用自定义插件
      app.use({
        install(app, config) {
          // 添加全局属性
          app.config.globalProperties.a = 10;
          app.config.globalProperties.fn = () => {
            console.log("fn");
          };
          // 添加全局组件
          app.component("Child", {
            template: `<div>child组件</div>`,
          });
          // 添加全局的依赖
          app.provide("count", 10);
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
